package cn.clq.ymcc.web.controller;

import cn.clq.ymcc.domain.Login;
import cn.clq.ymcc.service.IMessageStationService;
import cn.clq.ymcc.domain.MessageStation;
import cn.clq.ymcc.query.MessageStationQuery;
import cn.clq.ymcc.result.JSONResult;
import cn.clq.ymcc.result.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messageStation")
public class MessageStationController {

    @Autowired
    public IMessageStationService messageStationService;



    /**
     * @description: 课程发布成功之后，给相关用户发送短信
     * @param: dto
     * @return: cn.clq.ymcc.result.JSONResult
     * @author clqlongbao
     * @date: 2022/7/25 20:19
     */
    @PostMapping("/sendStation")
    public JSONResult sendSms(@RequestBody List<Login> logininfo){
        messageStationService.sendStation(logininfo);
        return JSONResult.success();
    }

    /**
    * 保存和修改公用的
    */
    @PostMapping("/save")
    public JSONResult saveOrUpdate(@RequestBody MessageStation messageStation){
        if(messageStation.getId()!=null){
            messageStationService.updateById(messageStation);
        }else{
            messageStationService.insert(messageStation);
        }
        return JSONResult.success();
    }

    /**
    * 删除对象
    */
    @DeleteMapping("/{id}")
    public JSONResult delete(@PathVariable("id") Long id){
        messageStationService.deleteById(id);
        return JSONResult.success();
    }

    /**
   * 获取对象
   */
    @GetMapping(value = "/{id}")
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(messageStationService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @GetMapping("/list")
    public JSONResult list(){
        return JSONResult.success(messageStationService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @PostMapping("/pagelist")
    public JSONResult page(@RequestBody MessageStationQuery query){
        Page<MessageStation> page = new Page<MessageStation>(query.getPage(),query.getRows());
        page = messageStationService.selectPage(page);
        return JSONResult.success(new PageList<MessageStation>(page.getTotal(),page.getRecords()));
    }
}
